﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PO_2011;

namespace WindowsFormsApplication1
{
    public partial class FiltrOgolny : Form
    {
        
        private Pnm p;
        private int MacierzWidthIHight = 7;
        public Form1 refToMainWindow;

        public FiltrOgolny(Pnm objectPnm)
        {
            InitializeComponent();
            p = objectPnm;

            foreach (System.Windows.Forms.TextBox c in this.tableLayoutPanel1.Controls)
            {
                System.Windows.Forms.TextBox z = c; z.Text="0";
            }
            pictureBox1.Size = new System.Drawing.Size(p.GetWidth, p.GetHeight);
            this.ClientSize = new System.Drawing.Size(p.GetWidth+588, p.GetHeight+100);
           pictureBox1.Image = p.getBitmap();
           this.textBox14.Text = "1"; comboBox1.Text = "7x7"; this.textBox14.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
        }
        // podglada oryginalu
        private void PokazPodglad(object sender, EventArgs e)
        {
            pictureBox1.Size = new System.Drawing.Size(p.GetWidth, p.GetHeight);
            pictureBox1.Image = p.getBitmap();
        }

        private void UstawZmiany(object sender, EventArgs e)
        {
            Double[,] Macierz = new Double[MacierzWidthIHight, MacierzWidthIHight];
            Double DzielnikNormalizowalny=0;
            int k = 0;
            if (MacierzWidthIHight == 5) k = 1;
            if (MacierzWidthIHight == 3) k = 2;
            for (int ii = 0+k; ii < MacierzWidthIHight+k; ii++)
                        {
                            for (int jj = 0+k; jj < MacierzWidthIHight+k; jj++)
                            {
                                System.Windows.Forms.TextBox z = (System.Windows.Forms.TextBox)tableLayoutPanel1.GetControlFromPosition(jj, ii);
                                Macierz[jj-k, ii-k] = Convert.ToDouble(z.Text);
                                DzielnikNormalizowalny += Macierz[jj-k, ii-k];
                            }
            }
           
                pictureBox1.Image = p.OgolnyFiltrUstaw(Macierz, DzielnikNormalizowalny, MacierzWidthIHight);
            }

        //metoda zmienia rozmiar macierzy 3x3,5x5,7x7
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            foreach (System.Windows.Forms.TextBox c in this.tableLayoutPanel1.Controls)
            {
                System.Windows.Forms.TextBox z = c; z.Text = "0";
            } this.textBox14.Text = "1";
            string s = comboBox1.SelectedItem.ToString();
            if (s == "3x3")
            {
                MacierzWidthIHight = 3;
                textBox1.ReadOnly = true;
                textBox4.ReadOnly = true;
                textBox5.ReadOnly = true;
                textBox3.ReadOnly = true;
                textBox8.ReadOnly = true;
                textBox32.ReadOnly = true;
                textBox44.ReadOnly = true;
                textBox39.ReadOnly = true;
                textBox37.ReadOnly = true;
                textBox38.ReadOnly = true;
                textBox40.ReadOnly = true;
                textBox41.ReadOnly = true;
                textBox7.ReadOnly = true;
                textBox16.ReadOnly = true;
                textBox18.ReadOnly = true;
                textBox24.ReadOnly = true;
                textBox31.ReadOnly = true;
                textBox45.ReadOnly = true;
                textBox46.ReadOnly = true;
                textBox47.ReadOnly = true;
                textBox48.ReadOnly = true;
                textBox49.ReadOnly = true;
                textBox43.ReadOnly = true;
                textBox42.ReadOnly = true;
                textBox6.ReadOnly = true;
                textBox11.ReadOnly = true;
                textBox12.ReadOnly = true;
                textBox9.ReadOnly = true;
                textBox33.ReadOnly = true;
                textBox34.ReadOnly = true;
                textBox35.ReadOnly = true;
                textBox36.ReadOnly = true;
                textBox29.ReadOnly = true;
                textBox30.ReadOnly = true;
                textBox27.ReadOnly = true;
                textBox26.ReadOnly = true;
                textBox28.ReadOnly = true;
                textBox25.ReadOnly = true;
                textBox23.ReadOnly = true;
                textBox21.ReadOnly = true;
            }
            else
                if (s == "7x7")
                {
                    MacierzWidthIHight = 7;
                    textBox1.ReadOnly = false;
                    textBox4.ReadOnly = false;
                    textBox5.ReadOnly = false;
                    textBox3.ReadOnly = false;
                    textBox8.ReadOnly = false;
                    textBox32.ReadOnly = false;
                    textBox44.ReadOnly = false;
                    textBox39.ReadOnly = false;
                    textBox37.ReadOnly = false;
                    textBox38.ReadOnly = false;
                    textBox40.ReadOnly = false;
                    textBox41.ReadOnly = false;
                    textBox7.ReadOnly = false;
                    textBox16.ReadOnly = false;
                    textBox18.ReadOnly = false;
                    textBox24.ReadOnly = false;
                    textBox31.ReadOnly = false;
                    textBox45.ReadOnly = false;
                    textBox46.ReadOnly = false;
                    textBox47.ReadOnly = false;
                    textBox48.ReadOnly = false;
                    textBox49.ReadOnly = false;
                    textBox43.ReadOnly = false;
                    textBox42.ReadOnly = false;
                }
                else
                {
                    textBox1.ReadOnly = true;
                    textBox4.ReadOnly = true;
                    textBox5.ReadOnly = true;
                    textBox3.ReadOnly = true;
                    textBox8.ReadOnly = true;
                    textBox32.ReadOnly = true;
                    textBox44.ReadOnly = true;
                    textBox39.ReadOnly = true;
                    textBox37.ReadOnly = true;
                    textBox38.ReadOnly = true;
                    textBox40.ReadOnly = true;
                    textBox41.ReadOnly = true;
                    textBox7.ReadOnly = true;
                    textBox16.ReadOnly = true;
                    textBox18.ReadOnly = true;
                    textBox24.ReadOnly = true;
                    textBox31.ReadOnly = true;
                    textBox45.ReadOnly = true;
                    textBox46.ReadOnly = true;
                    textBox47.ReadOnly = true;
                    textBox48.ReadOnly = true;
                    textBox49.ReadOnly = true;
                    textBox43.ReadOnly = true;
                    textBox42.ReadOnly = true;

                    textBox6.ReadOnly = false;
                    textBox11.ReadOnly = false;
                    textBox12.ReadOnly = false;
                    textBox9.ReadOnly = false;
                    textBox33.ReadOnly = false;
                    textBox34.ReadOnly = false;
                    textBox35.ReadOnly = false;
                    textBox36.ReadOnly = false;
                    textBox29.ReadOnly = false;
                    textBox30.ReadOnly = false;
                    textBox27.ReadOnly = false;
                    textBox26.ReadOnly = false;
                    textBox28.ReadOnly = false;
                    textBox25.ReadOnly = false;
                    textBox23.ReadOnly = false;
                    textBox21.ReadOnly = false;
                    MacierzWidthIHight = 5;
                }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.refToMainWindow.pictureBox1.Image = p.BitmapFiltr;
            p.bitmap = p.BitmapFiltr;
            this.Close();
        }

      }
    
}
